package com.xingkeduo.pojo.phppojo;

import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component;

/**
 * 返回实体
 *
 * @Description:
 * @Author:gaozifeng
 * @Date 2019/4/15 20:29
 **/
@Component
public class ResponseResult {

    private String error;

    private String reason;

    private Object content;

    public String success(Object content) {
        ResponseResult result = new ResponseResult();
        result.setContent(content).setError("0").setReason("0");
        return JSONObject.toJSONString(result);
    }

    public String success() {
        ResponseResult result = new ResponseResult();
        result.setContent("SUCCESS").setError("0").setReason("0");
        return JSONObject.toJSONString(result);
    }

    public ResponseResult successToJson(Object table) {
        ResponseResult result = new ResponseResult();
        result.setContent(table).setError("0").setReason("0");
        return result;
    }

    public String error(Object content) {
        ResponseResult result = new ResponseResult();
        result.setContent(content).setError("1").setReason("1");
        return JSONObject.toJSONString(result);
    }

    public String exceptionForTransfer(Object content, String reason) {
        ResponseResult result = new ResponseResult();
        result.setContent(content).setError("1").setReason(reason);
        return JSONObject.toJSONString(result);
    }

    public ResponseResult delException() {
        ResponseResult result = new ResponseResult();
        result.setContent("error").setError("1").setReason("请求失败");
        return result;
    }

    public String getError() {
        return error;
    }

    public ResponseResult setError(String error) {
        this.error = error;
        return this;
    }

    public String getReason() {
        return reason;
    }

    public ResponseResult setReason(String reason) {
        this.reason = reason;
        return this;
    }

    public Object getContent() {
        return content;
    }

    public ResponseResult setContent(Object content) {
        this.content = content;
        return this;
    }
}
